$(function () {
    getCompanyData();
})

function getCompanyData() {
    $.ajax({
        url: '/backCompanyFindAll',
        data: '',
        type: 'get',
        dataType: 'json',
        success: function (data) {
            setCompanyData(data[0].object);
        }
    })
}

function setCompanyData(data) {
    let html = '';
    for (let i = 0; i < data.length; i++) {
        html += '    <tr>\n' +
            '            <td>' + data[i].id + '</td>\n' +
            '            <td>' + data[i].name + '</td>\n' +
            '            <td>' + data[i].phone + '</td>\n' +
            '            <td><img src=" ' + data[i].logo + '" style="width: 30px;height: 30px;"/></td>\n' +
            '            <td>' + data[i].email + '</td>\n' +
            '            <td>' + data[i].net + '</td>\n' +
            '            <td><a href="javascript:toCompanyrEdit(' + data[i].id + ')"> 编辑</a>  ' +
            '<a href="javascript:UserDel(' + data[i].id + ')" >删除</a></td>\n' +
            '        </tr>';
    }
    $("#companyData").html(html);
}

function toCompanyrEdit(id) {
    sessionStorage.setItem("companyId", id);
    $('#backright').load('/back/companyAdd.jsp');
}